from scipy.ndimage.filters import generic_filter import numpy as np I_filt = generic_filter(I, np.std, size=3)